﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using SadlandVillage.Core;
using SadlandVillage.Core.Helper;

namespace SadlandVillage
{
    public class Credits : GameScene
    {
        #region Members and Properties
        private Dictionary<string, string[]> CreditsText;
        private const int TimeOffset= 1;
        private const int DeltaOffset = 2;

        Vector2 position;
        Vector2 initialBottom;
        int scrollTimeCounter = 0;
        Texture2D background;

        SpriteFont TitleFont;
        SpriteFont NormalFont;
        #endregion

        public Credits(ContentManager content, SpriteBatch spriteBatch, Vector2 bottom)
                : base(content, spriteBatch)
        {
            CreditsText = InitializeText();
            position = bottom;
            initialBottom = bottom;
        }

        #region Initialize Text
        private Dictionary<string, string[]> InitializeText()
        {
            Dictionary<string, string[]> result = new Dictionary<string, string[]>()
            {
                {
                    "SADLAND VILLAGE",new string[]{}
                },
                {
                    "Team", 
                    new[] 
                    {
                        "Alan Moura", 
                        "Amirton Chagas", 
                        "Edgar Neto", 
                        "João Gabriel Monteiro",
                        "Lucas Mello",
                        "Marcos Miguel",
                        "Nitai Bezerra",
                        "Rodrigo Lobo",
                        "Vitor Costa"
                     }
                },
                {
                    "Map, Menus, Fingertracking Interaction", 
                    new[]
                    {
                        "Edgar Neto",
                        "Nitai Bezerra",
                        "Rodrigo Lobo"
                    }
                },
                {
                    "Quickgames, Lumberjack game, River game",
                    new[]
                    {
                        "Alan Moura", 
                        "João Gabriel Monteiro",
                        "Vitor Costa"
                    }
                },
                {
                    "Pong Game, Mansion Game, Restaurant Game",
                    new[]
                    {
                        "Amirton Chagas",
                        "Lucas Melo",
                        "Marcos Miguel"
                    }
                },
                {
                    "",
                    new[]
                    {
                        "This game was developed by",
                        "graduation students and MSc candidates",
                        "of the Center of Informatics (CIn) from ",
                        "Federal University of Pernambuco (UFPE) ",
                        "as the Game Design and Implementation project for 2008.2"
                    }
                },
                {
                    "Professor",
                    new[]
                    {
                        "Geber Ramalho"
                    }
                }

                
            };

            return result;

        }
        #endregion Initialize Text

        public override void LoadContent()
        {
            TitleFont = content.Load<SpriteFont>(@"Credits\CreditsTitle");
            NormalFont = content.Load<SpriteFont>(@"Credits\Credits");
            background = content.Load<Texture2D>(@"Credits\creditos");
        }

        public override void Update(GameTime gameTime)
        {
            scrollTimeCounter++;

            if (scrollTimeCounter == TimeOffset)
            {
                position.Y -= DeltaOffset;
                scrollTimeCounter = 0;
            }
            if (Input.KeyPressed(Keys.Escape))
            {
                //Fire Event
                GlobalContainer.gameStateManager.SetCurrentState(GameState.Menu);
                position = initialBottom;
            }

        }

        public override void Draw(GameTime gameTime)
        {
            Vector2 offset = Vector2.Zero;
            
            spriteBatch.Begin();
            spriteBatch.Draw(background, Vector2.Zero, Color.White);
            
            foreach (var item in CreditsText)
            {
                spriteBatch.DrawString(TitleFont, item.Key, position + offset, Color.DarkGreen);
                offset.Y += TitleFont.LineSpacing;
                foreach (var textLine in item.Value)
                {
                    spriteBatch.DrawString(NormalFont, textLine, position + offset, Color.Green);
                    offset.Y += NormalFont.LineSpacing;
                }
                offset.Y += 20;
                
            }

            spriteBatch.End();
        }
    }


}
